//
//  GuanFangTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/4/6.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "GuanFangTableViewCell.h"

@implementation GuanFangTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 布局
- (void)addMySubview
{
    // 官方图片
    self.guanFangImageV = [[UIImageView alloc] initWithFrame:CGRectMake(13 * kAdjustParamater, 12 * kAdjustParamater, 180 * kAdjustParamater, 95 * kAdjustParamater)];
    self.guanFangImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.guanFangImageV.layer.cornerRadius = 7 * kAdjustParamater;
    self.guanFangImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_guanFangImageV];
    
    // 标题
    self.guanFangTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.guanFangImageV.right + 15 * kAdjustParamater, self.guanFangImageV.top + 4 * kAdjustParamater, 150 * kAdjustParamater, 15 * kAdjustParamater)];
 //   self.guanFangTitleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.guanFangTitleLabel.textAlignment = NSTextAlignmentLeft;
    self.guanFangTitleLabel.textColor = [UIColor blackColor];
    self.guanFangTitleLabel.font = [UIFont systemFontOfSize:k16Big];
    [self.contentView addSubview:_guanFangTitleLabel];
    
    // 时间
    self.guanFangTime = [[UILabel alloc] initWithFrame:CGRectMake(self.guanFangTitleLabel.left, self.guanFangImageV.top + 55 * kAdjustParamater, 150 * kAdjustParamater, 14 * kAdjustParamater)];
   // self.guanFangTime.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.guanFangTime.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    self.guanFangTime.textAlignment = NSTextAlignmentLeft;
    self.guanFangTime.font = [UIFont systemFontOfSize:k14Big];
    [self.contentView addSubview:_guanFangTime];
    
    // 头像
    self.peppleImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.guanFangTitleLabel.left + 2 * kAdjustParamater, self.guanFangTime.bottom + 8 * kAdjustParamater, 15 * kAdjustParamater, 15 * kAdjustParamater)];
    self.peppleImageV.image = [UIImage imageNamed:@"小人-01"];
    [self.contentView addSubview:_peppleImageV];
    
    // 人数
    self.memberCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.peppleImageV.right + 7 * kAdjustParamater, self.guanFangTime.bottom + 10 * kAdjustParamater, 25 * kAdjustParamater, 14 * kAdjustParamater)];
  //  self.memberCountLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.memberCountLabel.textColor = [UIColor colorWithRed:233/ 255.0 green:138 / 255.0 blue:30 / 255.0 alpha:1];
    self.memberCountLabel.font = [UIFont systemFontOfSize:k14Big];
    [self.contentView addSubview:_memberCountLabel];
    
    // 参加人
    self.joinLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.memberCountLabel.right, self.memberCountLabel.top, 50 * kAdjustParamater, 14 * kAdjustParamater)];
 //   self.joinLabel.backgroundColor = [UIColor redColor];
    self.joinLabel.text = @"人参加";
    self.joinLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    self.joinLabel.textAlignment = NSTextAlignmentLeft;
    self.joinLabel.font = [UIFont systemFontOfSize:k14Big];
    [self.contentView addSubview:_joinLabel];
    
    
}

- (void)setModel:(GuanFangActivityModel *)model
{
    self.guanFangTitleLabel.text = model.title;
    self.guanFangTime.text = model.time;
    self.memberCountLabel.text = [NSString stringWithFormat:@"%@", model.memberCount];
    
    
    // 动态进行标签
    // 初始化一个数进行记录
    CGFloat width = 0;
    NSArray *remarkArray = [model valueForKey:@"remark"];
    NSLog(@"remarkArray = %@", remarkArray);
    for (int i = 0; i < remarkArray.count; i++) {
            UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.guanFangTitleLabel.left +  width, self.guanFangTitleLabel.bottom + 12 * kAdjustParamater , 44 * kAdjustParamater, 17 * kAdjustParamater)];
            tempLabel.layer.borderColor = [[[UIColor blackColor] colorWithAlphaComponent:0.1] CGColor];
            tempLabel.layer.borderWidth = 1 * kAdjustParamater;
            tempLabel.backgroundColor = [UIColor whiteColor];
            tempLabel.text = remarkArray[i];
            tempLabel.textColor = [UIColor colorWithRed:233 / 255.0 green:138 / 255.0 blue:30 / 255.0 alpha:1];
            tempLabel.font = [UIFont systemFontOfSize:k13Big];
            tempLabel.textAlignment = NSTextAlignmentCenter;
            tempLabel.layer.cornerRadius = 2 * kAdjustParamater;
            // 进行动态调整
            CGRect newFrame = tempLabel.frame;
            newFrame.size.width = [[NetStatusHandle shareHandle] adjustWidth:tempLabel.text size:13 height:17] + 10 * kAdjustParamater;
            tempLabel.frame = newFrame;
            width = tempLabel.frame.size.width + 7 * kAdjustParamater + width;
            [self.contentView addSubview:tempLabel];
        
        
    }
    
    // 进行人数的动态调整
    CGRect newFrameTwo = self.memberCountLabel.frame;
    newFrameTwo.size.width = [[NetStatusHandle shareHandle] adjustWidth:self.memberCountLabel.text size:14 height:14];
    self.memberCountLabel.frame = newFrameTwo;
    
    self.joinLabel.frame = CGRectMake(self.memberCountLabel.right, self.joinLabel.frame.origin.y, self.joinLabel.frame.size.width, self.joinLabel.frame.size.height);
}

@end
